package com.buddy.lock.reentrantlock._09;

import java.util.concurrent.locks.ReentrantLock;

public class GetHoldCountService {
    private ReentrantLock lock = new ReentrantLock();

    public void serviceMethod1(){
        try {
            lock.lock();
            //查询当前线程保持此锁的个数，即调用lock方法的次数
            System.out.println("serviceMethod1 getHoldCount= "+lock.getHoldCount());
            serviceMethod2();
        }finally {
            lock.unlock();
        }
    }

    private void serviceMethod2() {
        try {
            lock.lock();
            System.out.println("serviceMethod2 getHoldCount= "+lock.getHoldCount());
        }finally {
            lock.unlock();
        }
    }
}
